package com.cnsugar.facerecgonized;

import com.cnsugar.ai.face.FaceHelper;
import com.cnsugar.ai.face.bean.Result;

import java.awt.image.BufferedImage;


/**
 * @Author ChenZhangKun
 * @Date 2020/4/17 10:59
 */
@SuppressWarnings("all")
public class FaceRunable implements Runnable {
    int i=0;
    @Override
    public void run() {
        while (true) {
            synchronized (FaceRunable.class) {
                long l = System.currentTimeMillis();
                if (FaceRe.imageList != null && FaceRe.imageList.size() > 0) {
                    BufferedImage image = FaceRe.imageList.get(0);
                    Result result = FaceHelper.search(image);
                    FaceRe.imageList.remove(0);
                    if (result != null) {
                        String name = result.getKey();
                        name = name.substring(0, name.length() - 4);
                        System.out.println("====");
                        System.out.println("名字是" + name);
                        System.out.println("相似度" + result.getSimilar());
                        System.out.println("搜索结果：" + result + "， 耗时：" + (System.currentTimeMillis() - l));
                        System.out.println(++i);
                        System.out.println("====");
                    } else {
                        System.out.println("====");
                        System.out.println("没有找到这个人");
                        System.out.println("耗时" + "  " + (System.currentTimeMillis() - l));
                        System.out.println(++i);
                        System.out.println("====");
                    }
                }
            }
        }
    }
}
